package com.javiercp.ayudaapp.contacts;

import java.util.ArrayList;

import android.content.ContentResolver;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;

public abstract class ContactAccessor {

	private static ContactAccessor mInstance;
	
	public static ContactAccessor getInstance() {
		if (mInstance == null) {
			String className;
			
			int sdkVersion = Integer.parseInt(Build.VERSION.SDK);
			if (sdkVersion < Build.VERSION_CODES.ECLAIR) {
				className = "ContactAccessorSDK3_4";
			}
			else {
				className = "ContactAccessorSDK5";
			}
			
			try {
				Class<? extends ContactAccessor> myClass = 
					Class.forName(ContactAccessor.class.getPackage().getName() + "." + className).asSubclass(ContactAccessor.class);
				
				mInstance = myClass.newInstance();
			} catch (Exception e) {
				throw new IllegalStateException(e);
			}
		}
		
		return mInstance;
	}
	
	public abstract Intent getPickContactIntent();
	
	public abstract ContactInfo loadContact(ContentResolver contentResolver, Uri contactUri);
	
	public abstract ArrayList<ContactPhone> getContactPhones(ContentResolver contentResolver, ContactInfo contactInfo);
	
	public abstract ArrayList<ContactEmail> getContactEmails(ContentResolver contentResolver, ContactInfo contactInfo);
}
